package com.thb.pay.web.controller;

import com.thb.pay.core.utils.R;
import com.thb.pay.service.OrderService;
import com.thb.pay.web.vo.CreateOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description 支付入口【创建订单】
 * @Author lucky
 * @data 2019/10/16 21:25
 */
@Slf4j
@Controller
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * @param createOrderVo 提交支付订单信息
     * @Description 创建支付订单
     * @Author lucky
     * @data 2019/10/16 21:30
     */
    @PostMapping(value = "/createOrder")
    @ResponseBody
    public R createOrder(@RequestBody @Validated CreateOrderVo createOrderVo) {
        long beginTimes = System.currentTimeMillis();
        if (log.isDebugEnabled()) {
            log.debug("<<<<<<<<<<<<<<<<<<<<<begin.create.order.requestTimes: " + beginTimes + " params:" + createOrderVo.toString() + ">>>>>>>>>>>>>>>>>>>>>>>>>>");
        }
        R resultData = orderService.createOrder(createOrderVo);
        long endTimes = System.currentTimeMillis();
        if (log.isDebugEnabled()) {
            log.debug("<<<<<<<<<<<<<<<<<<<<<end.create.order.consumerTimes: " + (endTimes - beginTimes) + ">>>>>>>>>>>>>>>>>>>>>>>>>>");
        }
        return resultData;
    }

}
